
 chimachima();
 function chimachima(){
 	  $("#chaxunchima").html("");
 	  $("#chanyongshe").html("");
	  $.ajax({
      url: urlcore+"/api/size/selectAllList3s",
			type: "get",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			success: function(data) {
				if(data.success == true) {
// 					  $.each(data.data.sizeList,function(y,n){
// 			    var chaxunchima='<li onclick="dianjisize(this)" id="'+n.id+'">'+n.sizeName+'</li>';
// 			    $("#chaxunchima").append(chaxunchima);
// 					  });
// 					  $.each(data.data.colourList,function(q,w){
// 					  	  var chanyongshe='	<dd>'+        
// '			<div id="yansheess" onclick="dianjiyanshe(this)" style="background-color: '+w.colourValue+'; border: 1px solid #E5E5E5;">'+
// '				<i style="display: inline;" class="open">'+
// '					<img  src="" />'+
// '         <input type="text" class="" id="'+w.id+'" value="'+w.colourName+'">'+
// '				</i>'+
// '			</div>'+
// '			<h6  class="colors">'+w.colourName+'</h6>'+
// '		</dd>';
//                $("#chanyongshe").append(chanyongshe);
// 					  });
				if(data.data.aguser.isMember==1){
			    if(data.data.aguser.memberTime!=null && data.data.aguser.memberTime!=""){
			  var oDate1 = new Date(data.data.aguser.memberTime);
              var oDate2 = new Date();
              if(oDate1.getTime()>oDate2.getTime()){
              	$("#dianhuahaoma2").val("y");
               	$("#youxiaoshijian").html('注：每天免费10条求购     (会员)剩余次数'+data.data.aguser.wantToBuyMemberCount+'');
              }else{
              	$("#dianhuahaoma2").val("n");
             	$("#youxiaoshijian").html('注：每天免费10条求购');
              }
			    	}
			    }else{
			    	$("#youxiaoshijian").html('注：每天免费10条求购');
			    }
			    
			    $("#dianhuahaoma").val(data.data.aguser.phone);
						 		$("#dianhua").html(data.data.aguser.phone);
					 }
		/*console.log(goodslist);*/
			},
			error: function() {
				alert("error");
			}
		});

 }
//选择商圈 
shangquan();
function shangquan(){
   $("#shangquansssss").html("");	
   $.ajax({
	url: urlcore + "/api/tradeArea/selectList",
	type: "get",
	dataType: 'json',
	contentType: "application/json;charset=utf-8",
	success: function(data) {
		if(data.success == true) {
		   var shangquansssss="";
		   $.each(data.data,function(y,n){
              shangquansssss+='<li><strong style="color:#000;line-height:54px;height:54px;margin-bottom:0" name="'+n.id+'" class="" onclick="shangquanid(this)">'+n.areaName+'</strong><div class="shangImg  shangImg'+n.id+'"><img  src="images/add/gou.png" /></div></li>';
		   });
		   $("#shangquansssss").append(shangquansssss);	
		} else if(data.code == 'OVERTIME') {
			var thisUrl = window.location.href;
			if(thisUrl.indexOf('1.0.0denglu.html') <= -1) {
				top.window.location.href = "1.0.0denglu.html";
			}
		} else {
			if(data.msg != '空数据') {
				alert(data.msg)
			} else {
				$('#thiscount').text(0);
			}
		}
	},
	error: function() {
		alert("error");
	}
     });	
		
    
}   	    
//选择每一个商圈 
function shangquanid(te){
	var sun=0;
	$(".sq_curr").each(function(){
			sun++;
	});
	if(sun<3){
	 if($(te).attr("class")==""){
		 $(te).css ('color', '#fd8f0e');
		 $(te).attr("class","sq_curr");
		 $('.shangImg'+$(te).attr('name')).show();
	  }else{
		  $(te).css ('color', '');
		  $(te).attr("class","");
		  $('.shangImg'+$(te).attr('name')).hide();
	  }
	}else{
		 $(te).css ('color', '');
		 $('.shangImg'+$(te).attr('name')).hide();
		 $(te).attr("class","");
	}
}
//确认商圈 
function querenshang(){
	var spri="";
	var suns=0;
	$(".sq_curr").each(function(){
		suns++;
		if(suns==1){
			 spri+=$(this).attr("name")+":"+$(this).html();
		}else if(suns==2){
			spri+=","+$(this).attr("name")+":"+$(this).html();
		}else if(suns==3){
			spri+=","+$(this).attr("name")+":"+$(this).html();
		}
		
	});
	jiexi(spri);
}
//渲染商圈 
function jiexi(str){
 if(str!=""){
 	var zhi2="";
 	var zhi="";
	var sss=str.split(",");	
	 $.each(sss, function(index, value) {
		var sunsss=0;
	   var vars=value.split(":");
		$.each(vars, function(indexs, valss) {
			sunsss++;
			if(sunsss==1){
				 zhi2+=valss+",";
				 $("#shangquanid").val(zhi2.slice(0,zhi2.length-1));
			}else{
				zhi+=valss+",";
				 $("#zhizhis").html(zhi.slice(0,zhi.length-1));
				 $('.payment_time_mask01').hide();
				 $('#bg').hide()
			}
	   });
	});
  }
  if($("#zhizhis").html().length>16){
	 $("#zhizhis").html($("#zhizhis").html().substr(0 , 16)+"...");
  }
}
//手机号码的隐藏和显示 
function yingchang(te){
	 console.log(te)
	 if($(te).attr("name")=="fr"){
		$(te).attr("name","br");
			$("#is_hidden").val(1);
			$("#dianhua").html($("#dianhua").html().substr(0 , 3)+"**** ****");
			$('.yuan1').show();
			$('.kai1').show();
			$('.yuan').hide();
			$('.kai').hide();
			$('.kaiguan').css({
				'border':'1px solid #aaa',
				'background':'#fff'
			})
			$('.kai').css('color','#fd900f');
		}else{
			$(te).attr("name","fr");
			$("#dianhua").html($("#dianhuahaoma").val());
			$("#is_hidden").val(0);
			$('.yuan').show();
			$('.kai').show();
			$('.yuan1').hide();
			$('.kai1').hide();
		
			$('.kaiguan').css({
				'background':'#fd900f',
				 'border':'1px solid #fd900f',

			});
			$('.kai').css('color','#fff');
		}
}
//渲染颜色 
yanse()
function yanse(){
	$.ajax({
	    url: urlcore+"/api/colour/selectListByUserId",
		type: "get",
		dataType: 'json',
		contentType: "application/json;charset=utf-8",
		success: function(data) {
		   if(data.success == true) {
			   $.each(data.data,function(q,w){
			   	  var chanyongshe='	<dd>'+        
			     '<div id="yansheess" onclick="dianjiyanse(this)" style="background: '+w.colourValue+'; border: 1px solid #E5E5E5;">'+
			      '</div>'+
			      '<h6 class="colors" name="'+w.id+'">'+w.colourName+'</h6>'+
			    '</dd>';
			   $("#chanyongshe").append(chanyongshe);
		       })
			   
			}  
		},
		error:function(){
			alert('error')
		}
	})
}
// 点击选择每个颜色
function dianjiyanse(te){ 
	   var colorid=$(te).next().attr("id");  
	   var colourName=$(te).next().html();
	   var op=$(te).next().attr('id'); 
	   if(op!="123s"){
		   $(te).next("h6").css("color","#FD900F");
		   $(te).next("h6").attr("id","123s");
	   }else{
	   	  $(te).next("h6").css("color","#333");
	 	  $(te).next("h6").attr("id","");
	   }
}
//添加颜色
function addNew(){
	if(uuuuid!=""){
	  var Newcolor=$("#Newcolor").val();
	  var zhi=$(".sp-input").val();
	  if(Newcolor.length<100){
	    if(Newcolor!=""){
			$.ajax({
				url:  urlcore +"/api/colour/addNew",///colour/addNew
				type: "post",/*  colourValue:zhi*/
				contentType: "application/json;charset=utf-8",
				data:JSON.stringify({
					colourName:Newcolor,
				}),
				dataType: "json",
				success:function(data){
				  // console.log(data)
				  if (data.success == true) {
						 chimachima(uuuuid);

					} else if (data.code == 'OVERTIME') {
						var thisUrl = window.location.href;
						if (thisUrl.indexOf('login.html') <= -1) {
							top.window.location.href = "1.0.0denglu.html";
						}
					} else {
						alert(data.msg);
					}
				},
				error: function() {
					alert("error");
				}
			});
	    }else{
	          	  	alert("标题不能为空");
	          	  }
	  }else{
			alert("标题过长");
			
	  }
	}else{
	   	alert("未登录/或登录超时");
	}    
} 
//完成颜色的选择然后渲染到input里面
function wanchengcolore(){
 	var colorname="";
 	var colorid="";
 	$("#colorid").val("");
 	$("#yanshes").html("");
 	$("#chanyongshe").find("h6").each(function(index,item){
 		if($(this).attr("id")=="123s"){
 			colorid+=$(this).attr("name")+",";
 			colorname+=$(this).html()+","; 
 		}
     });
 	var sizeidss=colorid.substring(0,colorid.length-1);
 	var sizeidsss=colorname.substring(0,colorname.length-1);
      if(sizeidsss==""){
      	   $("#yanshes").html("请选择(非必填)");
      }else{
      	   $("#yanshes").html(sizeidsss);
      }
 } 
// 渲染尺寸
chicun()
function chicun(){
   $.ajax({
   	url: urlcore+"/api/size/selectListByUserId",
   	type: "get",
   	dataType: 'json',
   	contentType: "application/json;charset=utf-8",
   	success: function(data) {
	  if(data.success == true) {
		$.each(data.data,function(y,n){
			var chaxunchima='<li onclick="dianjisize(this)" id="'+n.id+'">'+n.sizeName+'</li>';
			$("#chaxunchima").append(chaxunchima);

		})
	  }  
	},
	error:function(){
		alert('error')
	}
   })	
}
// 点击选择每个尺寸
function dianjisize(te){
	var sizeclass=$(te).attr("class");
	if(sizeclass=="p_chima_curr"){
		$(te).attr("class","");
	}else{
		$(te).attr("class","p_chima_curr");
	}

}
//添加尺寸
function addNew2(){
	   if(uuuuid!=""){
     	var sizeName=$("#sizeName").val();
	          if(sizeName.length<100){
	        if(sizeName!=""){
    $.ajax({
        url:  urlcore +"/api/size/addNew3",
        type: "post",
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify({
        	    userId:uuuuid,
        	   sizeName:sizeName
        }),
        dataType: "json",
        success:function(data){
            if (data.success == true) {
            	chimachima(uuuuid);
            } else if (data.code == 'OVERTIME') {
                var thisUrl = window.location.href;
                if (thisUrl.indexOf('login.html') <= -1) {
                    top.window.location.href = "1.0.0denglu.html";
                }
            } else {
                alert(data.msg);
            }
        },
        error: function() {
            alert("error");
        }
      });
	          	}
	          }else{
	          	alert("标题过长");
	          }
	   }else{
	   	alert("未登录/或登录超时");
	   }
}
//完成尺寸的选择然后渲染到input里面
function wanchengsize(){
	var sizeid="";
	var sizename="";
	$("#sizeid").val("");
	$("#chimas").html("");
	$("#chaxunchima").find("li").each(function(index,item){
		if($(this).attr("class")=="p_chima_curr"){
		  sizeid+=$(this).attr("id")+",";
		  sizename+=$(this).html()+",";
		}
	});
	var sizeidss=sizeid.substring(0,sizeid.length-1);
	var sizeidsss=sizename.substring(0,sizename.length-1);
    $("#sizeid").val(sizeidss);
    if(sizeidsss==""){
        $("#chimas").html("请选择(非必填)");
     }else{
     	$("#chimas").html(sizeidsss);
     }
}
function tijiao(){
    if(uuuuid!=''){
	    var xijie="";
		var shangpingfenlei='';
	    $(".classa").each(function(t,y){
	    	  xijie+=$(this).val()+"***";
			  shangpingfenlei+=$(this).val()+"***";

	    });
	     var xijietupian=xijie.substring(0,xijie.length-3);
	      var shangquanid=$("#shangquanid").val();//发布商圈   
		  var cityResult=$('#showCityPicker').val();//商品分类
	      var  dianhua=$("#dianhuahaoma").val();//电话dianhua
	      var username=$("#username").val();//联系人
	      var shuliang=$("#shuliang").val();//数量
	      var miaoshu=$("#miaoshu").val();//描述
	      var colorid=$("#colorid").val();//颜色
	      var sizeid=$("#sizeid").val();//尺码
	      var Backup=$("#Backup").val();
	      var fenleis=$("#sopey").html();//分类
	      var dianhuayingchang=$("#is_hidden").val();
	      var address=$("#cityResult3").html();
	      if(xijietupian==''){
			alert("请选择样本图片");  
		  } else if(shangquanid==""){
			  alert("请选择发布商圈");
			  
	      }else if(cityResult==""){
			  console.log(cityResult)
			 alert("请选择商品分类");
		  } else if(shuliang==""){
	      	alert("请填写需要数量"); 
// 			if(shuliang<=0){
// 			$("#shuliang").val('输入的数量有误')	
// 			}
	      }else if(address==""){
	      	 alert("请选择需求地址");
	      }else if(fenleis!="0" && fenleis!="undefined"){
			  $.ajax({
				url:  urlcore + "/api/wantBuy/add",///wantBuy/add
				type: "post",
				contentType: "application/json;charset=utf-8",
				data: JSON.stringify({
					   userId:uuuuid,
					   tradeAreaId:shangquanid,
					   // coverUrl:fengmain,
					   goodsUrl:xijietupian,
					   sortTypeId:fenleis,
					   phone:dianhua,
					   contactName:username,
					   goodsNum:shuliang,
					   goodsDescribe:miaoshu,
					   colourId:colorid,
					   sizeId:sizeid,
					   address:address,
					   qq:Backup,
					   isHidden:dianhuayingchang
				}),
				dataType: "json",
				success:function(data){
					console.log(data)
					if (data.success == true) {
							if (confirm("发布成功，是否继续添加？")) {
								//刷新
								location.reload();
							} else {
								//跳转列表页
								window.location.href = "4.2.0qiugou.html";
							}
					} else if (data.code == 'OVERTIME') {
						var thisUrl = window.location.href;
						if (thisUrl.indexOf('login.html') <= -1) {
							//top.window.location.href = "1.0.0denglu.html";
						}
					} else {
						alert(data.msg);
					}
				},
				error: function() {
					alert("error");
				}
			 });
         }
    }else{
	  alert("未登录/或登录超时");
    }
}








